//
//  UIImage+HBExtension.swift
//  sinaWeibo
//
//  Created by Beans on 16/7/1.
//  Copyright © 2016年 iceWorks. All rights reserved.
//

import UIKit

extension UIImage {

    /// 获取当前屏幕截图
    class func getScreenShot() -> UIImage {
        // 1. 获取当前window
        let window = UIApplication.sharedApplication().keyWindow!
        // 2. 开启绘图
        // size: 大小; opaque: 是否透明; scale: 缩放系数
        UIGraphicsBeginImageContextWithOptions(kScreenSize, false, 1.0)
        // 3. 把window画在画板上
        window.drawViewHierarchyInRect(kScreenBounds, afterScreenUpdates: false)
        // 4. 拿到image
        let image = UIGraphicsGetImageFromCurrentImageContext()
        // 5. 关闭画板
        UIGraphicsEndImageContext()
        
        return image
    }
}
